package com.shiyu.system.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.sql.SQLOutput;

//加密算法工具类
public class BcryptUtils {
//    生成加密后的密码
    public static String encryptPassword(String password){
        BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
        return passwordEncoder.encode(password);
    }
//    判断密码是否相同
//    rawpassword 用户输入的密码
//    encodePassword 从数据库中查出来的密码
//    根据数据库中的密码得到盐值
    public static boolean matchesPassword(String rawPassword,String encodePassword){
        BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
        return passwordEncoder.matches(rawPassword,encodePassword);
    }

    public static void main(String[] args) {
        System.out.println(encryptPassword("123456"));
      //  System.out.println(matchesPassword("123456","$2a$10$Ponig3a8ES0P0nna9v2Mf.ukPrGagn3TIzxdj4LO9nCDQ1SMmRqL2"));
    }
}
